package com.example.rabbitmqdemo.hellorabbitmq.exclusive;

import com.example.rabbitmqdemo.hellorabbitmq.CommonUtil;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

class CommonConnection {

    private Connection connection;

    private CommonConnection() {
        ConnectionFactory factory = CommonUtil.getFactory();
        try {
            this.connection = factory.newConnection();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (TimeoutException e) {
            e.printStackTrace();
        }
    }

    static class Factory {
        private static CommonConnection connection = new CommonConnection();

        public static Connection getConntion() {
            return connection.connection;
        }
    }


}
